package com.lk.servlet;

import com.lk.entity.User;
import com.lk.service.UserService;
import com.lk.service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/Delete")
public class UserDeleteServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String userId= request.getParameter("userId");
        UserService userService=new UserServiceImpl();
        int i=Integer.parseInt(userId);
        int n= userService.deleteUser(i);

        if (n==1){
            request.setAttribute("userId",userId);
            request.getRequestDispatcher("userList.jsp").forward(request,response);

        } else if (n==0) {
            request.setAttribute("userId","");
        }
        request.getRequestDispatcher("userDelete.html").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
